<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<title>{echo admin_title()}</title>
<!--header-->
{template _:header}
</head>
<body>
<div class="layui-layout layui-layout-admin">
<!--top-->
{template _main_top}
<!--nav-->
{template _main_nav}
	<div class="position"><h1>商户列表</h1></div>
	<div class="layui-body admin-body">
		<div class="admin-content">
			<div class="searcher">
				<form name="sch_form" id="sch_form" method="get" action="{echo \befen\get_url()}">
					<div class="layui-input-inline"><input type="text" name="merchant_name" id="merchant_name" class="layui-input" value="{echo input('param.merchant_name')}" placeholder="商户编号或名称"></div>
					<div class="layui-input-inline layui-left-margin"><button type="submit" id="search" class="layui-btn">查询</button></div>
					<div class="layui-input-inline layui-left-margin"><button type="submit" name="action" value="export" class="layui-btn">导出</button></div>
				</form>
				<div class="clear"></div>
			</div>
			<form name="theform" id="theform" method="post" action="{echo \befen\get_url()}">
			<table class="layui-table">
				<thead>
					<tr>
						<th>商户名称</th>
						<th>商户编号</th>
						<th>申请时间</th>
						<th>商户状态</th>
						<th>费率</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
					<!--{loop $list $key $val}-->
					<tr id="">
						<td>{$val[merchant_name]}</td>
						<td>{$val[merchant_no]}</td>
						<td>{php}echo gsdate('Y-m-d', $val['time_create']){/php}</td>
						<td class="op"><span class="layui-badge layui-bg-status-{$val[status]}">{echo model('Merchant')->getStatus($val['status'])}</span></td>
						<td class="op"><span class="layui-badge layui-badge-rim">{echo number_format($val['trade_rates'], 2)}%</span></td>
						<td class="op">
							<a op="detail" lay-url="{echo url('merchant/detail', ['merchant_id' => $val['merchant_id']])}" class="layui-btn layui-btn-xs layui-btn-normal">商户详情</a>
							<a op="device" lay-url="{echo url('device/index', ['merchant_id' => $val['merchant_id']])}" class="layui-btn layui-btn-xs layui-btn-normal">终端设备</a>
							<a op="auth" merchant_id="{$val[merchant_id]}" merchant_name="{$val[merchant_name]}" class="layui-btn layui-btn-xs layui-btn-normal">商户授权</a>
							<a op="passwd" lay-url="{echo url('merchant/passwd', ['merchant_id' => $val['merchant_id']])}" class="layui-btn layui-btn-xs layui-btn-normal">重置密码</a>
						</td>
					</tr>
					<!--{/loop}-->
				</tbody>
			</table>
			</form>
			<div class="listpages">{$pagenav}</div>
		</div>
	</div>
</div>
<!--footer-->
{template _:footer}
<script type="text/javascript">
$(".layui-add").click(function(){
	showWindow('添加商户', '{echo url('merchant/add')}', '800px');
});
$("a[op=detail]").click(function(){
	showWindow('商户详情', $(this).attr('lay-url'), '800px');
});
$("a[op=device]").click(function(){
	gotourl($(this).attr('lay-url'));
});
$("a[op=passwd]").click(function(){
	showWindow('重置密码', $(this).attr('lay-url'), '300px');
});
$("a[op=auth]").click(function(){
	var merchant_id = $(this).attr('merchant_id');
	var merchant_name = $(this).attr('merchant_name');
	$.ajax({
		type: "POST",
		dataType: "html",
		timeout: 30000,
		url: "{echo url('merchant/get_url_auth_token')}",
		data: {
			ajax: "html",
			merchant_id: merchant_id,
		},
		success: function(html){
			init_Layer(function(){
				layer.open({
					title: '商户授权 - ' + merchant_name,
					shade: 0.5,
					isOutAnim: true,
					content: '<div style="text-align:center"><div id="auth_qrcode" style="width:250px;height:250px;margin:0 auto 1em;"></div><h3>请引导商户扫描此二维码进行授权</h3></div>',
					btn: false
				});
				var qrcode = new QRCode(document.getElementById("auth_qrcode"), {
					width: 250,
					height: 250
				});
				qrcode.makeCode(html);
			});
		},
		complete: function(){
			hideLoader();
		},
		beforeSend: function(){
			showLoader();
		}
	});
});
$('#sch_form input[name=merchant_name]').autoComplete({
	url: "{echo url('merchant/index')}",
	field: "merchant_no",
	value: "{echo input('param.merchant_name')}",
	name_hidden: "merchant_id",
	value_hidden: "{echo input('param.merchant_id')}",
});
</script>
</body>
</html>